#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <getopt.h>
#include "lire_option.h"

void init_option(Option * o){
	o->host=NULL;
	o->port=NULL;
	o->user=NULL;
	o->pass=NULL;
	o->nomfic=NULL;
	o->debug = 0;
}



int lire_option(int argc, char *argv[],Option * o)
{
	int val;
	
	init_option(o);
  
	while ((val = getopt(argc, argv, "h:p:u:P:f:d")) != -1)
	{
    		switch (val)
		{
   			case 'h':
      				o->host = optarg;
      			break;

    			case 'p':
      				o->port = optarg;
      			break;
    			
			case 'u':
				o->user = optarg;
			break;
			
			case 'P':
				o->pass = optarg;
			break;
			
			case 'f':
				o->nomfic = optarg;
			break;
			
			case 'd':
      				o->debug++;
      			break;

			default :
				fprintf(stderr, "l'option %c est inconnue ou mal utilisée\n", optopt);
				exit(1);
		}
	}
	
	if(o->host==NULL){
		o->host = "ftp.univ-lyon1.fr";
	}
	
	if(o->port==NULL){
		o->port = "21";
	}
	
	
	if(o->user==NULL){
		o->user = "anonymous";
	}
	
	
	if(o->pass==NULL){
		o->pass = "mail@gmail.com";
	}
	return 0;
}
